import request from '@/utils/request'

export function getRoleDetail(id) {
  return request({
    url: '/sys/user/' + id
  })
    .then(res => res.data.data)
    .catch(() => ({}))
}

export function getRoleList() {
  return request({
    url: '/sys/role'
  })
    .then(res => res.data.data.rows)
    .catch(() => [])
}

export function updateRoleDetail(id, roleIds) {
  return request({
    url: '/sys/user/assignRoles',
    method: 'put',
    data: {
      id,
      roleIds
    }
  })
    .then(res => res.data.message)
    .catch(err => Promise.reject(err.response.data.message))
}
